(function() {
	module('PhotoPuzzle Tests');

	test('Setup OK', function() {
		ok(true);
	});

	test('Initial state', function() {
		var view = new TestView();
		var shuffledPositions = [ 2, 6, 3, 4, 5, 1 ];
		var controller = new PhotoPuzzle(view, shuffledPositions);

		controller.startup();

		var expected = {
			positions : shuffledPositions,
			selected : -1
		};

		deepEqual(view.state, expected);
	});

	test('Test select element', function() {
		var view = new TestView();
		var shuffledPositions = [ 2, 6, 3, 4, 5, 1 ];
		var controller = new PhotoPuzzle(view, shuffledPositions);

		controller.startup();
		controller.onSelect(2);

		var expected = {
			positions : shuffledPositions,
			selected : 2
		};

		deepEqual(view.state, expected);
	});

	test('Test swap elements', function() {
		var view = new TestView();
		var shuffledPositions = [ 1, 2, 3, 4, 5, 6 ];
		var controller = new PhotoPuzzle(view, shuffledPositions);

		controller.startup();
		controller.onSelect(2);
		var swapped = controller.onSwap(3);

		ok(swapped);

		var expected = {
			positions : [ 1, 2, 4, 3, 5, 6 ],
			selected : -1
		};

		deepEqual(view.state, expected);
	});

	test('Test swap same element', function() {
		var view = new TestView();
		var shuffledPositions = [ 1, 2, 3, 4, 5, 6 ];
		var controller = new PhotoPuzzle(view, shuffledPositions);

		controller.startup();
		controller.onSelect(2);
		controller.onSwap(2);

		var expected = {
			positions : [ 1, 2, 3, 4, 5, 6 ],
			selected : -1
		};

		deepEqual(view.state, expected);
	});

	test('Test swap a solution', function() {
		var view = new TestView();
		var shuffledPositions = [ 2, 6, 3, 4, 5, 1 ];
		var controller = new PhotoPuzzle(view, shuffledPositions);

		controller.startup();

		controller.onSelect(0);
		controller.onSwap(5);// [ 1, 6, 3, 4, 5, 2 ]
		ok(!view.onSolvedCalled);

		controller.onSelect(1);
		controller.onSwap(5);// [ 1, 2, 3, 4, 5, 6 ]
		ok(view.onSolvedCalled);

		var expected = {
			positions : [ 1, 2, 3, 4, 5, 6 ],
			selected : -1
		};

		deepEqual(view.state, expected);
	});

	function TestView() {
		this.onSolvedCalled = false;
	}

	TestView.prototype.init = function(controller) {
	};

	TestView.prototype.update = function(state) {
		this.state = state;
	};

	TestView.prototype.onSolved = function() {
		this.onSolvedCalled = true;
	};

}());